(function (global, factory) {
	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('stat/vue'), require('stat/client')) :
	typeof define === 'function' && define.amd ? define(['stat/vue', 'stat/client'], factory) :
	(global.stat = factory(global.vueStat,global.client));
}(this, (function (vueStat,client) { 'use strict';

	vueStat = vueStat && vueStat.hasOwnProperty('default') ? vueStat['default'] : vueStat;

	var wnlCore = (function (router, _ref) {
		var _ref$showConsole = _ref.showConsole,
		    showConsole = _ref$showConsole === undefined ? false : _ref$showConsole,
		    _ref$oncePageView = _ref.oncePageView,
		    oncePageView = _ref$oncePageView === undefined ? false : _ref$oncePageView,
		    _ref$onceNodeView = _ref.onceNodeView,
		    onceNodeView = _ref$onceNodeView === undefined ? true : _ref$onceNodeView,
		    _ref$metaPageName = _ref.metaPageName,
		    metaPageName = _ref$metaPageName === undefined ? 'cnzz' : _ref$metaPageName,
		    _ref$metaPageParamsGe = _ref.metaPageParamsGet,
		    metaPageParamsGet = _ref$metaPageParamsGe === undefined ? 'getParams' : _ref$metaPageParamsGe,
		    _ref$isWnl = _ref.isWnl,
		    isWnl = _ref$isWnl === undefined ? false : _ref$isWnl;
		return {
			install: function install(vue) {
				var getSdkData = client.GetSdkData(vue);
				var hostSdk = void 0;
				try {
					if (!isWnl) throw new Error('not isWnl');
					hostSdk = require('host-sdk');
				} catch (err) {
					console.log('%c ' + err, 'color: red;');

					hostSdk = {
						setShareParam: function setShareParam() {
							console.log('%c setShareParam not wnl!', 'color: red;');
						},
						stat_wnl: function stat_wnl() {
							console.log('%c stat_wnl not wnl!', 'color: red;');
						},
						uploadPageEndStatistics: function uploadPageEndStatistics() {
							console.log('%c uploadPageEndStatistics not wnl!', 'color: red;');
						}
					};
				}

				vueStat.set({
					from: 'wnl',
					router: router,
					metaPageName: metaPageName,
					metaPageParamsGet: metaPageParamsGet,
					report: function report(data, opt) {
						var _data = getSdkData(data);

						showConsole && console.log('%c' + _data, 'color: blue;');

						hostSdk.stat_wnl(_data, opt);
					},
					oncePageView: oncePageView,
					onceNodeView: onceNodeView
				});
				vue.use(vueStat);

				vue.prototype.$setShareParam = function (data) {
					showConsole && console.log('%c $setShareParam', 'color: blue;', data);

					var bookId = data.bookId,
					    method = data.method,
					    param = data.param;


					hostSdk.setShareParam({ data: { sourceType: 0, param: param, 'book_id': bookId || '', method: method || 1 } });
				};

				var time = Date.now();
				var time2 = 0;
				var diff = 0;
				var count = 0;
				var updateTime = function updateTime() {
					time2 = Date.now();
					diff = time2 - time;
					time = time2;

					return true;
				};
				var getDiffData = function getDiffData() {
					return { pageName: JSON.parse(getSdkData())[0].parentPage, duration: diff };
				};

				router.afterEach(function () {
					return count++ && setTimeout(function () {
						return updateTime() && hostSdk.uploadPageEndStatistics(getDiffData());
					}, 200);
				});
			}
		};
	});

	return wnlCore;

})));
